#AutoIt3Wrapper_Icon=icon.ico
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Comment=CodeQ code editor
#AutoIt3Wrapper_Res_Description=CodeQ code editor
#AutoIt3Wrapper_Res_Fileversion=1.2.0.1
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#AutoIt3Wrapper_Res_LegalCopyright=Copyright © 2013 Sycam Inc
#AutoIt3Wrapper_Res_Field=Made By|sean campbell
#AutoIt3Wrapper_Res_Field=Email|sycam.inc@gmail.com
#AutoIt3Wrapper_Res_Field=Compile Date|%date% %time%
#AutoIt3Wrapper_Res_Field=Productname|CodeQ code editor for multiple language
#AutoIt3Wrapper_Res_Field=ProductVersion|Version 1.2.0.1
#AutoIt3Wrapper_Res_Field=CompanyName|Sycam Inc
#AutoIt3Wrapper_Res_Field=Credits|sean campbell (Creator)
#AutoIt3Wrapper_Res_Field=Credits|kip (SciLexer UDF)
#AutoIt3Wrapper_Au3Check_Stop_OnWarning=y
#AutoIt3Wrapper_Run_Tidy=n
#AutoIt3Wrapper_Run_Au3Check=y
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_Run_cvsWrapper=v
#AutoIt3Wrapper_cvsWrapper_Parameters=/Comments %fileversion%
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiToolbar.au3>
#include <Constants.au3>
#include <GuiStatusBar.au3>
#include <GuiEdit.au3>
#include <GuiTab.au3>
#include <_SciLexer.au3>
#include <Array.au3>
#include <WinAPI.au3>
#Include <GuiMenu.au3>
#Include <String.au3>
#include <Timers.au3>
#Include <File.au3>
#include <tabconstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#Include <GuiButton.au3>
#include <file2.au3>

Global $lf1 = "", $lf2 = "", $lf3 = "", $lf4 = ""
Global $ActiveSci = 0
Global $ref1[100]
Global $ref2[100]
Global $ref3[100]
Global $ref4[100]
Global $ref5[100]
Global $ref6[100]
Global $ref7[100]
Global $MaxSci[1][6]
Global $avl[13]
Global $au31 = _CLRL_read(@ScriptDir & "\api\AU3\AU3.AC.CLRL","functions")
Global $au32 = _CLRL_read(@ScriptDir & "\api\AU3\AU3.AC.CLRL","hash")
Global $au33 = _CLRL_read(@ScriptDir & "\api\AU3\AU3.AC.CLRL","macros")
Global $au34 = _CLRL_read(@ScriptDir & "\api\AU3\AU3.AC.CLRL","UDFS")
Global $au3i = _CLRL_read(@ScriptDir & "\api\AU3\AU3.AC.CLRL","imports")
Global $au3ii = IniRead(@ScriptDir & "\api\au3\config.ini","config","import","")
Global $au3run = IniRead(@ScriptDir & "\api\au3\config.ini","config","runpath","")

Global $java1 = _CLRL_read(@ScriptDir & "\api\java\java.AC.CLRL","m1")
Global $java2 = _CLRL_read(@ScriptDir & "\api\java\java.AC.CLRL","m2")
Global $java3 = _CLRL_read(@ScriptDir & "\api\java\java.AC.CLRL","m3")
Global $java4 = _CLRL_read(@ScriptDir & "\api\java\java.AC.CLRL","m4")
Global $javai = _CLRL_read(@ScriptDir & "\api\java\java.AC.CLRL","imports")
Global $javaii = IniRead(@ScriptDir & "\api\java\config.ini","config","import","")
Global $javarun = IniRead(@ScriptDir & "\api\java\config.ini","config","runpath","")

Global $c1 = _CLRL_read(@ScriptDir & "\api\c\C.AC.CLRL","functions")
Global $c2 = _CLRL_read(@ScriptDir & "\api\c\C.AC.CLRL","macros")
Global $c3 = _CLRL_read(@ScriptDir & "\api\c\C.AC.CLRL","other")
Global $c4 = _CLRL_read(@ScriptDir & "\api\c\C.AC.CLRL","udfs")
Global $ci = _CLRL_read(@ScriptDir & "\api\c\C.AC.CLRL","imports")
Global $cii = IniRead(@ScriptDir & "\api\c\config.ini","config","import","")
Global $crun = IniRead(@ScriptDir & "\api\c\config.ini","config","runpath","")

Global $ch1 = _CLRL_read(@ScriptDir & "\api\c#\C#.AC.CLRL","functions")
Global $ch2 = _CLRL_read(@ScriptDir & "\api\c#\C#.AC.CLRL","macros")
Global $ch3 = _CLRL_read(@ScriptDir & "\api\c#\C#.AC.CLRL","other")
Global $ch4 = _CLRL_read(@ScriptDir & "\api\c#\C#.AC.CLRL","UDFS")
Global $chi = _CLRL_read(@ScriptDir & "\api\c#\C#.AC.CLRL","imports")
Global $chii = iniread(@ScriptDir & "\api\c#\config.ini","config","import","")
Global $chrun = iniread(@ScriptDir & "\api\c#\config.ini","config","runpath","")

Global $cpp1 = _CLRL_read(@ScriptDir & "\api\c++\C++.AC.CLRL","functions")
Global $cpp2 = _CLRL_read(@ScriptDir & "\api\c++\C++.AC.CLRL","macros")
Global $cpp3 = _CLRL_read(@ScriptDir & "\api\c++\C++.AC.CLRL","other")
Global $cpp4 = _CLRL_read(@ScriptDir & "\api\c++\C++.AC.CLRL","UDFS")
Global $cppi = _CLRL_read(@ScriptDir & "\api\c++\C++.AC.CLRL","imports")
Global $cppi = iniread(@ScriptDir & "\api\c++\config.ini","config","import","")
Global $cpprun = iniread(@ScriptDir & "\api\c++\config.ini","config","runpath","")

Global $Fas1 = _CLRL_read(@ScriptDir & "\api\fas\Fas.AC.CLRL","functions")
Global $fas2 = _CLRL_read(@ScriptDir & "\api\fas\fas.AC.CLRL","macros")
Global $fas3 = _CLRL_read(@ScriptDir & "\api\fas\fas.AC.CLRL","other")
Global $fas4 = _CLRL_read(@ScriptDir & "\api\fas\fas.AC.CLRL","UDFS")
Global $fasi = _CLRL_read(@ScriptDir & "\api\fas\fas.AC.CLRL","imports")
Global $fasii = iniread(@ScriptDir & "\api\fas\config.ini","config","import","")
Global $fasrun = iniread(@ScriptDir & "\api\fas\config.ini","config","runpath","")

Global $php1 = _CLRL_read(@ScriptDir & "\api\php\php.AC.CLRL","functions")
Global $php2 = _CLRL_read(@ScriptDir & "\api\php\php.AC.CLRL","macros")
Global $php3 = _CLRL_read(@ScriptDir & "\api\php\php.AC.CLRL","other")
Global $php4 = _CLRL_read(@ScriptDir & "\api\php\php.AC.CLRL","UDFS")
Global $phpi = _CLRL_read(@ScriptDir & "\api\php\php.AC.CLRL","imports")
Global $phpii = iniread(@ScriptDir & "\api\php\config.ini","config","import","")
Global $phprun = iniread(@ScriptDir & "\api\php\config.ini","config","runpath","")

Global $pyt1 = _CLRL_read(@ScriptDir & "\api\pyt\pyt.AC.CLRL","functions")
Global $pyt2 = _CLRL_read(@ScriptDir & "\api\pyt\pyt.AC.CLRL","macros")
Global $pyt3 = _CLRL_read(@ScriptDir & "\api\pyt\pyt.AC.CLRL","other")
Global $pyt4 = _CLRL_read(@ScriptDir & "\api\pyt\pyt.AC.CLRL","UDFS")
Global $pyti = _CLRL_read(@ScriptDir & "\api\pyt\pyt.AC.CLRL","imports")
Global $pytii = iniread(@ScriptDir & "\api\pyt\config.ini","config","import","")
Global $pytrun = iniread(@ScriptDir & "\api\pyt\config.ini","config","runpath","")

Global $lua1 = _CLRL_read(@ScriptDir & "\api\lua\lua.AC.CLRL","functions")
Global $lua2 = _CLRL_read(@ScriptDir & "\api\lua\lua.AC.CLRL","macros")
Global $lua3 = _CLRL_read(@ScriptDir & "\api\lua\lua.AC.CLRL","other")
Global $lua4 = _CLRL_read(@ScriptDir & "\api\lua\lua.AC.CLRL","UDFS")
Global $luai = _CLRL_read(@ScriptDir & "\api\lua\lua.AC.CLRL","imports")
Global $luaii = iniread(@ScriptDir & "\api\lua\config.ini","config","import","")
Global $luarun = iniread(@ScriptDir & "\api\lua\config.ini","config","runpath","")

Global $js1 = _CLRL_read(@ScriptDir & "\api\js\js.AC.CLRL","functions")
Global $js2 = _CLRL_read(@ScriptDir & "\api\js\js.AC.CLRL","macros")
Global $js3 = _CLRL_read(@ScriptDir & "\api\js\js.AC.CLRL","other")
Global $js4 = _CLRL_read(@ScriptDir & "\api\js\js.AC.CLRL","UDFS")
Global $jsi = _CLRL_read(@ScriptDir & "\api\js\js.AC.CLRL","imports")
Global $jsii = iniread(@ScriptDir & "\api\js\config.ini","config","import","")
Global $jsrun = iniread(@ScriptDir & "\api\js\config.ini","config","runpath","")

Global $txt = ";"
Global $UtB = 1, $tabs[1], $maxtabs = 5
Global $el = @DesktopWidth -25
Global $eh = @DesktopHeight -125
Global $cotabs = 1
Global $tabz[1]
Global $Gui = GUICreate("CodeQ Code editor (dev.net)", 800, 700, -1, -1, $WS_MAXIMIZE + $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX + $WS_CAPTION + $WS_POPUP + $WS_SYSMENU)
GUISetState(@SW_SHOW)
$iFile = GUICtrlCreateMenu("&File")
$iFile_New = GUICtrlCreateMenuItem("&New" & @TAB & "Ctrl+N", $iFile)
GUICtrlCreateMenuItem("", $iFile)
$iFile_Open = GUICtrlCreateMenuItem("&Open" & @TAB & "Ctrl+O", $iFile)
$iFile_Save = GUICtrlCreateMenuItem("&Save" & @TAB & "Ctrl+S", $iFile)
$iFile_SaveAs = GUICtrlCreateMenuItem("Save &As" & @TAB & "Ctrl+Shift+S", $iFile)
GUICtrlCreateMenuItem("", $iFile)
$iFile_Exit = GUICtrlCreateMenuItem("E&xit" & @TAB & "Esc", $iFile)

$iEdit = GUICtrlCreateMenu("&Edit")
$iEdit_Undo = GUICtrlCreateMenuItem("&Undo" & @TAB & "Ctrl+Z", $iEdit)
$iEdit_Redo = GUICtrlCreateMenuItem("&Redo" & @TAB & "Ctrl+Y", $iEdit)
GUICtrlCreateMenuItem("", $iEdit)
$iEdit_Cut = GUICtrlCreateMenuItem("Cu&t" & @TAB & "Ctrl+X", $iEdit)
$iEdit_Copy = GUICtrlCreateMenuItem("&Copy" & @TAB & "Ctrl+C", $iEdit)
$iEdit_Paste = GUICtrlCreateMenuItem("&Paste" & @TAB & "Ctrl+V", $iEdit)
GUICtrlCreateMenuItem("", $iEdit)
$iEdit_Search = GUICtrlCreateMenuItem("&Search" & @TAB & "Ctrl+S", $iEdit)

$ilang = GUICtrlCreateMenu("Languages")
$ilang_AU3 = GUICtrlCreateMenuItem("Autoit", $ilang)
$ilang_C3 = GUICtrlCreateMenu("C", $ilang)
$ilang_C = GUICtrlCreateMenuItem("&C", $ilang_C3)
$ilang_Ch = GUICtrlCreateMenuItem("&C#", $ilang_C3)
$ilang_Cp = GUICtrlCreateMenuItem("&C++", $ilang_C3)
$ilang_FAS = GUICtrlCreateMenuItem("Flash Action Script", $ilang)
$ilang_J = GUICtrlCreateMenu("J", $ilang)
$ilang_java = GUICtrlCreateMenuItem("&Java code", $ilang_j)
$ilang_js = GUICtrlCreateMenuItem("&JavaScript", $ilang_j)
$ilang_LUA = GUICtrlCreateMenuItem("LUA", $ilang)
$ilang_TXT = GUICtrlCreateMenuItem("Normal", $ilang)
$ilang_P = GUICtrlCreateMenu("p", $ilang)
$ilang_PHP = GUICtrlCreateMenuItem("PHP", $ilang_P)
$ilang_PY = GUICtrlCreateMenuItem("python", $ilang_P)

$iTools = GUICtrlCreateMenu("&Tools")
$iTools_Runfile = GUICtrlCreateMenuItem("&Run" & @TAB & "F5", $iTools)
GUICtrlCreateMenuItem("", $iTools)
$iTools_Settings = GUICtrlCreateMenuItem("&Settings", $iTools)
$iplugin = GUICtrlCreateMenu("Plugin Functions")

_plugin_int()


Global $AccelKeys[6][2]
$AccelKeys[0][0] = "^n"
$AccelKeys[0][1] = $iFile_New
$AccelKeys[1][0] = "^o"
$AccelKeys[1][1] = $iFile_Open
$AccelKeys[2][0] = "^s"
$AccelKeys[2][1] = $iFile_Save
$AccelKeys[3][0] = "^+s"
$AccelKeys[3][1] = $iFile_SaveAs
$AccelKeys[4][0] = "{Esc}"
$AccelKeys[4][1] = $iFile_Exit
$AccelKeys[5][0] = "{F5}"
$AccelKeys[5][1] = $iTools_Runfile

GUISetAccelerators($AccelKeys)

$hStatus = _GUICtrlStatusBar_Create($Gui)

Local $aParts[5] = [10, 200, 400, 600, 800]

_GUICtrlStatusBar_SetParts($hStatus, $aParts)
Global $iSearchInput = GUICtrlCreateInput("", 0, 0, 200, 16)
Global $hSearchInput = GUICtrlGetHandle($iSearchInput)
_GUICtrlStatusBar_EmbedControl($hStatus, 1, $hSearchInput)
$bt = 18
$aSize = WinGetClientSize($Gui)
$itbn = GUICtrlCreateIcon("smallIcons.dll", -1771, 0, 0, 17, 17)
$itbo = GUICtrlCreateIcon("smallIcons.dll", -1287, $bt, 0, 17, 17)
$itbsa = GUICtrlCreateIcon("smallicons.dll", -1303, $bt + $bt, 0, 17, 17)
$itbx = GUICtrlCreateIcon("smallicons.dll", -1129, $bt + $bt + $bt + $bt, 0, 17, 17)
$itbc = GUICtrlCreateIcon("smallicons.dll", -111, $bt + $bt + $bt + $bt + $bt, 0, 17, 17)
$itbp = GUICtrlCreateIcon("smallicons.dll", -9, $bt + $bt + $bt + $bt + $bt + $bt, 0, 17, 17)
$itbcl = GUICtrlCreateIcon("smallicons.dll", -611, $bt + $bt + $bt + $bt + $bt + $bt + $bt, 0, 17, 17)
$itbu = GUICtrlCreateIcon("smallicons.dll", -728, $bt + $bt + $bt + $bt + $bt + $bt + $bt + $bt + $bt, 0, 17, 17)
$itbre = GUICtrlCreateIcon("smallicons.dll", -194, $bt + $bt + $bt + $bt + $bt + $bt + $bt + $bt + $bt + $bt, 0, 17, 17)
$itbs = GUICtrlCreateIcon("smallicons.dll", -511, $bt + $bt + $bt + $bt + $bt + $bt + $bt + $bt + $bt + $bt + $bt + $bt, 0, 17, 17)
$itbrun = GUICtrlCreateIcon("shell32.dll", -138, $bt + $bt + $bt + $bt + $bt + $bt + $bt + $bt + $bt + $bt + $bt + $bt + $bt, 0, 17, 17)

$aStatusbarSize = WinGetClientSize($hStatus)

Global $iClientX = 0
Global $iClientY = 30
Global $iClientWidth = $aSize[0]
Global $iClientHeight = $aSize[1] - 30 - $aStatusbarSize[1]
Global $iTabHeight = 24
Global $iFileTab = GUICtrlCreateTab($iClientX, $iClientY + 2, $iClientWidth + 2, $iTabHeight - 1, $TCS_FOCUSNEVER, $TCS_EX_REGISTERDROP)
Global $hFileTab = GUICtrlGetHandle($iFileTab)
if $cmdline[0] > 0 Then
	_new($cmdline[1])
Else
	_new()
EndIf
_sci_int()
GUIRegisterMsg($WM_NOTIFY, "WM_AC")
While 1
	$Msg = GUIGetMsg()
	Switch $Msg
		Case $itbrun
			_run()
		Case $iTools_Settings
			_settings()
		Case $iTools_Runfile
			_run()
		Case $itbcl
			_dc()
		Case $iEdit_Copy
			sci_copy($maxsci[$ActiveSci][0])
		Case $iEdit_Cut
			sci_cut($maxsci[$ActiveSci][0])
		Case $iEdit_Paste
			sci_paste($maxsci[$ActiveSci][0])
		case $iEdit_Redo
			sci_redo($maxsci[$ActiveSci][0])
		Case $iEdit_Undo
			sci_undo($maxsci[$ActiveSci][0])
		Case $iEdit_Search
			search()
		Case $iFile_SaveAs
			_save(1)
		Case $itbs
			search()
		Case $itbu
			sci_undo($MaxSci[$ActiveSci][0])
		Case $itbre
			sci_redo($MaxSci[$ActiveSci][0])
		Case $itbx
			Sci_Cut($MaxSci[$ActiveSci][0])
		Case $itbc
			sci_copy($MaxSci[$ActiveSci][0])
		Case $itbp
			sci_paste($MaxSci[$ActiveSci][0])
		Case $itbn
			_new()
		Case $itbo
			_open()
		Case $itbsa
			_save(0)
		Case $GUI_EVENT_CLOSE
			_close()
		Case $iFile_Exit
			_close()
		Case $iFile_new
			_new()
		Case $ifiletab
			$tab = GUICtrlRead($ifiletab) + 1
			_document_switch($tab)
		Case $iFile_Open
			_open()
		Case $ilang_AU3
			$ref1[$ActiveSci] = $au31
			$ref2[$ActiveSci] = $au32
			$ref3[$ActiveSci] = $au33
			$ref4[$ActiveSci] = $au34
			$ref5[$activesci] = $au3i
			$ref6[$activesci] = $au3ii
			$ref7[$ActiveSci] = "au3"
			_sci_au3()
		Case $ilang_txt
			$ref1[$ActiveSci] = $txt
			$ref2[$ActiveSci] = $txt
			$ref3[$ActiveSci] = $txt
			$ref4[$ActiveSci] = $txt
			$ref5[$ActiveSci] = $txt
			$ref7[$activesci] = "txt"
			_sci_int()
		Case $ilang_java
			$ref1[$ActiveSci] = $java1
			$ref2[$ActiveSci] = $java2
			$ref3[$ActiveSci] = $java3
			$ref4[$ActiveSci] = $java4
			$ref5[$ActiveSci] = $javai
			$ref6[$ActiveSci] = $javaii
			$ref7[$ActiveSci] = "java"
			_sci_int()
		Case $ilang_C
			$ref1[$ActiveSci] = $c1
			$ref2[$ActiveSci] = $c2
			$ref3[$ActiveSci] = $c3
			$ref4[$ActiveSci] = $c4
			$ref5[$ActiveSci] = $ci
			$ref6[$ActiveSci] = $cii
			$ref7[$ActiveSci] = "c"
			_sci_int()
		Case $ilang_Ch
			$ref1[$ActiveSci] = $ch1
			$ref2[$ActiveSci] = $ch2
			$ref3[$ActiveSci] = $ch3
			$ref4[$ActiveSci] = $ch4
			$ref5[$ActiveSci] = $chi
			$ref6[$ActiveSci] = $chii
			$ref7[$ActiveSci] = "C#"
			_sci_int()
		Case $ilang_Cp
			$ref1[$ActiveSci] = $cpp1
			$ref2[$ActiveSci] = $cpp2
			$ref3[$ActiveSci] = $cpp3
			$ref4[$ActiveSci] = $cpp4
			$ref5[$ActiveSci] = $cppi
			$ref6[$ActiveSci] = $cppii
			$ref7[$ActiveSci] = "C++"
			_sci_int()
		Case $ilang_FAS
			$ref1[$ActiveSci] = $Fas1
			$ref2[$ActiveSci] = $fas2
			$ref3[$ActiveSci] = $fas3
			$ref4[$ActiveSci] = $fas4
			$ref5[$ActiveSci] = $fasi
			$ref6[$ActiveSci] = $fasii
			$ref7[$ActiveSci] = "As"
			_sci_int()
		Case $ilang_js
			$ref1[$ActiveSci] = $js1
			$ref2[$ActiveSci] = $js2
			$ref3[$ActiveSci] = $js3
			$ref4[$ActiveSci] = $js4
			$ref5[$ActiveSci] = $jsi
			$ref6[$ActiveSci] = $jsii
			$ref7[$ActiveSci] = "js"
			_sci_int()
		Case $ilang_LUA
			$ref1[$ActiveSci] = $LUA1
			$ref2[$ActiveSci] = $LUA2
			$ref3[$ActiveSci] = $LUA3
			$ref4[$ActiveSci] = $LUA4
			$ref5[$ActiveSci] = $LUAi
			$ref6[$ActiveSci] = $LUAii
			$ref7[$ActiveSci] = "Lua"
			_sci_int()
		Case $ilang_PHP
			$ref1[$ActiveSci] = $PHP1
			$ref2[$ActiveSci] = $PHP2
			$ref3[$ActiveSci] = $PHP3
			$ref4[$ActiveSci] = $PHP4
			$ref5[$ActiveSci] = $PHPi
			$ref6[$ActiveSci] = $PHPii
			$ref7[$ActiveSci] = "Php"
			_sci_int()
		Case $ilang_PY
			$ref1[$ActiveSci] = $PYT1
			$ref2[$ActiveSci] = $PYT2
			$ref3[$ActiveSci] = $PYT3
			$ref4[$ActiveSci] = $PYT4
			$ref5[$ActiveSci] = $PYTi
			$ref6[$ActiveSci] = $PYTii
			$ref7[$ActiveSci] = "Py"
			_sci_int()
		Case $iFile_Save
			_save(0)
		Case $iFile_SaveAs
			_save(1)
	EndSwitch
	
WEnd

Func _Document_Create($sPath)
	Global $SCN_IGN = 1
	$sPathSplit = StringSplit($sPath, "\")
	$sTitle = $sPathSplit[$sPathSplit[0]]
	If not $sPath Then
		$sTitle = "Untitled"
		$sScript = ""
		_GUICtrlStatusBar_SetText($hStatus, $sTitle, 2)
	Else
		
		$hFile = FileOpen($sPath, 0)
		$sScript = FileRead($hFile)
		FileClose($hFile)
		_GUICtrlStatusBar_SetText($hStatus, $sTitle, 2)
	EndIf
	
	GUISwitch($Gui)
	$iTab = GUICtrlCreateTabItem($sTitle)
	;GUICtrlSetData($iTab,$iTab)
	
	;MsgBox(0,"sds",$iTab)
	_GUICtrlStatusBar_SetText($hStatus, "", 3)
	$Sci = Sci_CreateEditor($Gui, $iClientX, $iClientY + $iTabHeight, $iClientWidth, $iClientHeight - $iTabHeight)
	Sci_SetSelectionbkColor($Sci, 0xFFA3A3)
	Sci_AutoCompleteActive($Sci)
	GUICtrlCreateTabItem("")
	
	;SendMessage($Sci, $SCI_SETMODEVENTMASK, $SC_MOD_INSERTTEXT+$SC_MOD_DELETETEXT, 0) ; only text modifications will be notified
	
	ReDim $MaxSci[UBound($MaxSci) + 1][6]
	$iID = UBound($MaxSci) - 1
	$MaxSci[$iID][0] = $Sci
	$MaxSci[$iID][1] = $iTab
	$MaxSci[$iID][2] = ""
	$MaxSci[$iID][3] = ""
	$MaxSci[$iID][4] = $sPath
	$MaxSci[$iID][5] = ""
	_Document_Switch($iID)
	_sci_int()
	$ref1[$ActiveSci] = $txt
	$ref2[$ActiveSci] = $txt
	$ref3[$ActiveSci] = $txt
	$ref4[$ActiveSci] = $txt
	$ref5[$ActiveSci] = $txt
	$ref6[$ActiveSci] = $txt
	$ref7[$ActiveSci] = "txt"
	Sci_AddLines($Sci, $sScript, 0)
	
	$iLen = Sci_GetLenght($Sci)
	Sci_SetCurrentPos($Sci, $iLen)
	
	Sci_EmptyUndoBuffer($Sci)
	
	Sci_BeginUndoAction($Sci)
	
	;SendMessage($Sci, $SCI_SETFOCUS, 1, 0)
	
	;Global $tStruct = DllStructCreate("int")
	;DllStructSetData($tStruct, 1, 34)
	;DllStructSetData($tStruct, 2, $sPath)
	
	;Message_Broadcast($PLGN_GUI, 3, DllStructGetPtr($tStruct))
	Global $SCN_IGN = 0
	Return $iID
	
EndFunc

Func _Document_Switch($iID)
	Global $SCN_IGN = 1
	If $ActiveSci = $iID Then Return 0
	
	If $ActiveSci Then
		
		_WinAPI_ShowWindow($MaxSci[$ActiveSci][0], @SW_HIDE)
	EndIf
	
	GUICtrlSetState($MaxSci[$iID][1], $GUI_SHOW)
	
	_WinAPI_ShowWindow($MaxSci[$iID][0], @SW_SHOW)
	$AC_iLines = Sci_GetLineCount($MaxSci[$iID][0])
	$ActiveSci = $iID
	Return 1
	Global $SCN_IGN = 0
EndFunc

Func WM_AC($hWndGUI, $MsgID, $wParam, $lParam)
	
	Local $tagNMHDR = DllStructCreate("int;int;int;int;int;int;int;ptr;int;int;int;int;int;int;int;int;int;int;int", $lParam)
	
	$hWndFrom = DllStructGetData($tagNMHDR, 1)
	$IdFrom = DllStructGetData($tagNMHDR, 2)
	$Event = DllStructGetData($tagNMHDR, 3)
	$Position = DllStructGetData($tagNMHDR, 4)
	$Ch = DllStructGetData($tagNMHDR, 5)
	$Modifiers = DllStructGetData($tagNMHDR, 6)
	$ModificationType = DllStructGetData($tagNMHDR, 7)
	$Char = DllStructGetData($tagNMHDR, 8)
	$Length = DllStructGetData($tagNMHDR, 9)
	$LinesAdded = DllStructGetData($tagNMHDR, 10)
	$Message = DllStructGetData($tagNMHDR, 11)
	$uptr_t = DllStructGetData($tagNMHDR, 12)
	$sptr_t = DllStructGetData($tagNMHDR, 13)
	$Line = DllStructGetData($tagNMHDR, 14)
	$FoldLevelNow = DllStructGetData($tagNMHDR, 15)
	$FoldLevelPrev = DllStructGetData($tagNMHDR, 16)
	$Margin = DllStructGetData($tagNMHDR, 17)
	$ListType = DllStructGetData($tagNMHDR, 18)
	$X = DllStructGetData($tagNMHDR, 19)
	$Y = DllStructGetData($tagNMHDR, 20)
	$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
	$iCode = DllStructGetData($tNMHDR, "Code")
	Switch $Event
		Case $SCN_CHARADDED
			$Word = _GetCurrentWord($MaxSci[$ActiveSci][0])
			If StringInStr($ref1[$ActiveSci], $word) Then
				Sci_AutoCompleteShow($MaxSci[$ActiveSci][0], StringLen($Word), $ref1[$ActiveSci])
			elseIf StringInStr($ref2[$ActiveSci], $word) Then
				Sci_AutoCompleteShow($MaxSci[$ActiveSci][0], StringLen($Word), $ref2[$ActiveSci])
			elseIf StringInStr($ref3[$ActiveSci], $word) Then
				Sci_AutoCompleteShow($MaxSci[$ActiveSci][0], StringLen($Word), $ref3[$ActiveSci])
			ElseIf StringInStr($ref4[$ActiveSci], $Word) Then
				sci_autocompleteshow($MaxSci[$ActiveSci][0], StringLen($Word), $ref4[$ActiveSci])
			ElseIf $word = $ref6[$ActiveSci] Then
				sci_autocompleteshow($MaxSci[$activesci][0],0,$ref5[$activesci])
			EndIf
			_GUICtrlStatusBar_SetText($hStatus, "modified", 3)
			_GUICtrlStatusBar_SetText($hStatus, $Word, 4)
			If _getcurrentchar($maxsci[$ActiveSci][0]) = " " or _getcurrentchar($maxsci[$ActiveSci][0]) = ")" or _getcurrentchar($maxsci[$ActiveSci][0]) = "(" or _getcurrentchar($maxsci[$ActiveSci][0]) = @LF Then
				sci_endundoaction($MaxSci[$ActiveSci][0])
				sci_beginundoaction($MaxSci[$ActiveSci][0])
			EndIf
	EndSwitch
	;ToolTip($iItem &"  "& $Toolbar_New)
EndFunc ;==>WM_AC

func _GetCurrentWord($Sci)
	
	$CurrentPos = Sci_GetCurrentPos($Sci)
	
	SendMessageString($Sci, $SCI_SETWORDCHARS, 0, '<>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$#@""')
	
	$iStartPos = SendMessage($Sci, $SCI_WORDSTARTPOSITION, $CurrentPos, True)
	$iEndPos = SendMessage($Sci, $SCI_WORDENDPOSITION, $CurrentPos, True)
	
	If $iStartPos = $iEndPos Then Return ""
	
	$iLine = Sci_GetCurrentLine($Sci)
	$iLinePos = Sci_GetLineStartPos($Sci, $iLine - 1)
	
	$sLine = Sci_GetLine($Sci, $iLine - 1)
	
	$sWord = StringMid($sLine, $iStartPos - $iLinePos + 1, $iEndPos - $iStartPos)
	
	Return $sWord
	
EndFunc ;==>_GetCurrentWord

Func _getcurrentchar($sci)
	$scp = sci_getcurrentpos($sci) - 1
	Return sci_getchar($sci, $scp)
EndFunc


Func _Open()
	
	$sFile = FileOpenDialog("CodeQ - Open File", "", "All Files (*.*)")
	If @error Or Not $sFile Then Return
	_BackUp()
	
	_New($sFile)
	
EndFunc ;==>_Open

Func _New($sPath = "")
	
	_BackUp()
	
	$iID = _Document_Create($sPath)
	Sci_SetSavePoint($MaxSci[$ActiveSci][0])
	$hi = StringSplit($spath,"\")
	If FileExists($sPath) Then
		$MaxSci[$ActiveSci][4] = $hi[$hi[0]]
		$lang = StringSplit($spath,".")
		Switch $lang[$lang[0]]
			Case "au3"
				$ref1[$ActiveSci] = $au31
				$ref2[$ActiveSci] = $au32
				$ref3[$ActiveSci] = $au33
				$ref4[$ActiveSci] = $au34
				$ref5[$activesci] = $au3i
				$ref6[$activesci] = $au3ii
				$ref7[$ActiveSci] = "au3"
				_sci_au3()
		EndSwitch
	EndIf
EndFunc ;==>_New

Func _Save($iSaveAS = 1, $iID = $ActiveSci)
	$ltd = "." & $ref7[$iid]
	
	If Not $MaxSci[$iID][4] Or $iSaveAS Then
		$savFile = FileSaveDialog("Save file as...", @WorkingDir, "current source(*." & $ref7[$iid] & ")", 16, "", $Gui)
			$len = StringLen($ref7[$iid])
	  If StringRight($savFile, $len) <> $ref7[$iid] Then $savFile &= $ltd
	Else
		$savFile = $MaxSci[$iID][4]
	EndIf
	If @error Or Not $savFile Then Return
	
	_BackUp()
	$MaxSci[$iID][4] = $savFile
	
	Sci_SetSavePoint($maxsci[$iID][0])
	
	$sPathSplit = StringSplit($savFile, "\")
	$sTitle = $sPathSplit[$sPathSplit[0]]
	
	GUICtrlSetData($MaxSci[$iID][1], $sTitle)
	
	$hFile = FileOpen($savFile, 2)
	FileWrite($hFile, stringtrimright(Sci_GetText($MaxSci[$iID][0]),1))
	FileClose($hFile)
	
	_GUICtrlStatusBar_SetText($hStatus, "Unmodified", 3)
	Return $savFile
EndFunc ;==>_Save

Func _BackUp($iID = 0)
	
	$iStart = 1
	$iEnd = UBound($maxsci) - 1
	
	If $iID Then
		$iStart = $iID
		$iEnd = $iID
	EndIf
	
	For $i = $iStart To $iEnd
		
		If Not $maxsci[$i][4] Then
			
			$sFilename = "Untitled.uniscr"
			$sFoldername = "None" & $iID
			
		Else
			
			$aPathSplit = StringSplit($maxsci[$i][4], "\")
			$sFilename = $aPathSplit[$aPathSplit[0]]
			$sFoldername = $aPathSplit[$aPathSplit[0] - 1]
			
		EndIf
		
		$sBackupFolder = "[" & $sFoldername & "] " & $sFilename
		
		If Not FileExists("Backup\" & $sBackupFolder) Then DirCreate("Backup\" & $sBackupFolder)
		
		$sBackupFile = @MON & "." & @MDAY & "." & @YEAR & " [" & @HOUR & "." & @MIN & "." & @SEC & "].tmp"
		
		$File = FileOpen("Backup\" & $sBackupFolder & "\" & $sBackupFile, 2)
		
		FileWrite($File, Sci_GetText($maxsci[$i][0]))
		
		FileClose($File)
		
	Next
	
EndFunc ;==>_BackUp

Func search()
	$sar = GUICreate("search", 455, 155, -1, -1, -1, $WS_EX_TOOLWINDOW + $WS_EX_CONTEXTHELP)
	GUICtrlCreateLabel("Find What?", 20, 10, 65, 15, -1, -1)
	$st = GUICtrlCreateInput("", 20, 30, 310, 20, -1, 512)
	$rc = GUICtrlCreateCheckbox("Replace", 20, 60, 60, 20, -1, -1)
	GUICtrlCreateLabel("Replace with", 20, 90, 75, 15, -1, -1)
	$rt = GUICtrlCreateInput("", 20, 110, 312, 20, -1, 512)
	$go = GUICtrlCreateButton("Go!", 340, 30, 100, 100, 14, -1)
	DllCall("user32.dll", "UINT", "SendMessage", "handle", GUICtrlGetHandle($go), "UINT", $BCM_SETNOTE, "ptr*", 0, "wstr", "search and replace")
	DllCall("user32.dll", "UINT", "SendMessage", "handle", GUICtrlGetHandle($go), "UINT", $BCM_SETSHIELD, "ptr*", 0, "BOOL", false)
	GUISetState(@SW_SHOW, $sar)
	
	While 1
		$nMsg = GUIGetMsg()
		Switch $nMsg
			Case $GUI_EVENT_CLOSE
				GUIDelete($sar)
				ExitLoop
			Case $go
				SendMessageString($Sci, $SCI_SETWORDCHARS, 0, '<>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";:?/.,{}[]\|+=-)(*&^%$#@!~`')
				$spos = Sci_Search($MaxSci[$ActiveSci][0], GUICtrlRead($st))
				$epos = SendMessage($Sci, $SCI_WORDENDPOSITION, $spos, True)
				sci_setselection($MaxSci[$ActiveSci][0], $spos, $epos)
				If GUICtrlRead($rc) = 1 and $epos > 0 Then
					Sci_ReplaceSel($MaxSci[$ActiveSci][0], GUICtrlRead($rt))
				EndIf
		EndSwitch
	WEnd
EndFunc ;==>search

Func _Document_Close($iID)
	
	$iEditorsLeft = 0
	
	For $i = 1 To UBound($maxsci) - 1
		If $maxsci[$i][0] Then
			
			$iEditorsLeft += 1
		EndIf
	Next
	
	If $iEditorsLeft = 1 Then
		_WinAPI_MessageBeep(1)
		Return 0
	EndIf
	
	_WinAPI_DestroyWindow($maxsci[$iID][0])
	GUICtrlDelete($maxsci[$iID][1])
	
	;MsgBox(0,"sdsd",$maxsci[$iID][1])
	
	$maxsci[$iID][0] = 0
	$maxsci[$iID][1] = 0
	$maxsci[$iID][2] = ""
	$maxsci[$iID][3] = ""
	$maxsci[$iID][4] = ""
	$maxsci[$iID][5] = ""
	
	;$activesci = 0
	
	For $i = 1 To UBound($maxsci) - 1
		If $maxsci[$i][0] Then
			_Document_Switch($i)
			ExitLoop
		EndIf
	Next
	
	Return 1
	
EndFunc ;==>_Document_Close

Func _close()
	$id = MsgBox(3, "", "the program is closing, do you want to save changes?")
	Switch $id
		Case 6
			Do
				_save(0)
				If Not $ActiveSci Then
					_document_close($ActiveSci)
				Else
					ExitLoop
				Endif
			Until $ActiveSci = 0
			Exit
		Case 7
			Exit
	EndSwitch
EndFunc

Func _dc()
	If $ActiveSci = 1 Then
		MsgBox(0, "", "you can't close the 1st tab")
	Else
		If MsgBox(4, "", "Are you sure you want to discard this document (this action cannot be undone)") = 6 Then
			_document_close($ActiveSci)
		EndIf
	EndIf
EndFunc

Func _run()
	Switch $ref7[$ActiveSci]
		Case "au3"
			If _isrealstring($au3run) Then
				$if = _save(0)
				If FileExists($if) Then
					Run($au3run & ' "' & $if & '"')
				EndIf
			Else
				MsgBox(0, "", "Coufigure run settings by going tools -> settings- > configure run paths")
			EndIf
		Case "C"
			If _isrealstring($crun) Then
				$if = _save(0)
				If FileExists($if) Then
					Run($crun & ' "' &  $if & '"')
				EndIf
			Else
				MsgBox(0, "", "Coufigure run settings by going tools -> settings- > configure run paths")
			EndIf
		Case "C#"
			If _isrealstring($chrun) Then
				$if = _save(0)
				If FileExists($if) Then
					Run($chrun & ' "' & $if & '"')
				EndIf
			Else
				MsgBox(0, "", "Coufigure run settings by going tools -> settings- > configure run paths")
			EndIf
		Case "C++"
			If _isrealstring($cpprun) Then
				$if = _save(0)
				If FileExists($if) Then
					Run($cpprun & ' "' & $if & '"')
				EndIf
			Else
				MsgBox(0, "", "Coufigure run settings by going tools -> settings- > configure run paths")
			EndIf
		Case "as"
			If _isrealstring($fasrun) Then
				$if = _save(0)
				If FileExists($if) Then
					Run($fasrun, $if)
				EndIf
				Else
					MsgBox(0, "", "Coufigure run settings by going tools -> settings- > configure run paths")
				EndIf
			Case "Php"
				If _isrealstring($Phprun) Then
					$if = _save(0)
					If FileExists($if) Then
						Run($phprun & ' "' & $if & '"')
					EndIf
				Else
					MsgBox(0, "", "Coufigure run settings by going tools -> settings- > configure run paths")
				EndIf
			Case "py"
				If _isrealstring($pytrun) Then
					$if = _save(0)
					If FileExists($if) Then
						Run($pytrun & ' "' & $if & '"')
					EndIf
				Else
					MsgBox(0, "", "Coufigure run settings by going tools -> settings- > configure run paths")
				EndIf
			Case "lua"
				If _isrealstring($laurun) Then
					$if = _save(0)
					If FileExists($if) Then
						Run($luarun  & ' "' &  $if & '"')
					EndIf
				Else
					MsgBox(0, "", "Coufigure run settings by going tools -> settings- > configure run paths")
				EndIf
			Case "java"
				MsgBox(0, "", "Unfortunatly you cannot run java source files in this vertion. In later vertions of CodeQ you will be able to run .java files due to the soon to be added java compiler")
			Case "txt"
				MsgBox(0, "", "you cant run a txt file")
		EndSwitch
EndFunc

Func _settings()
	$settings = GUICreate("settings", 500, 240, -1, -1, -1, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)
	GUISetBkColor(0xFFFFFF, $settings)
	$sgro = GUICtrlCreateGroup("run paths", 138, 54, 360, 185, -1, -1)
	$au3rp = GUICtrlCreateInput("autoit run path", 148, 79, 100, 20, -1, 512)
	$ab = GUICtrlCreateButton("Browse", 248, 79, 50, 20, -1, -1)
	$crp = GUICtrlCreateInput("C run path", 148, 109, 100, 20, -1, 512)
	$cb = GUICtrlCreateButton("Browse", 248, 109, 50, 20, -1, -1)
	$chrp = GUICtrlCreateInput("C# run path", 148, 139, 100, 20, -1, 512)
	$chb = GUICtrlCreateButton("Browse", 248, 139, 50, 20, -1, -1)
	$cpprp = GUICtrlCreateInput("C++ run path", 148, 169, 100, 20, -1, 512)
	$cppb = GUICtrlCreateButton("Browse", 248, 169, 50, 20, -1, -1)
	$fasrp = GUICtrlCreateInput("Flash As run path", 148, 199, 100, 20, -1, 512)
	$fasb = GUICtrlCreateButton("Browse", 248, 199, 50, 20, -1, -1)
	$jrp = GUICtrlCreateInput("Java run path", 338, 79, 100, 20, -1, 512)
	$jsrp = GUICtrlCreateInput("Js run path", 338, 109, 100, 20, -1, 512)
	$lrp = GUICtrlCreateInput("LUA run path", 338, 139, 100, 20, -1, 512)
	$phprp = GUICtrlCreateInput("Php run path", 338, 169, 100, 20, -1, 512)
	$pyrp = GUICtrlCreateInput("Python run path", 338, 199, 100, 20, -1, 512)
	$jb = GUICtrlCreateButton("Browse", 438, 79, 50, 20, -1, -1)
	$jsb = GUICtrlCreateButton("Browse", 438, 109, 50, 20, -1, -1)
	$luab = GUICtrlCreateButton("Browse", 438, 139, 50, 20, -1, -1)
	$phpb = GUICtrlCreateButton("Browse", 438, 169, 50, 20, -1, -1)
	$pyb = GUICtrlCreateButton("Browse", 438, 199, 50, 20, -1, -1)
	GUICtrlCreateGroup("info", 2, 54, 130, 185, -1, -1)
	GUICtrlCreateLabel("CodeQ code editor", 10, 80, 92, 15, -1, -1)
	GUICtrlSetBkColor(-1, "-2")
	GUICtrlCreateLabel("Version : 1.0 Initial  Release", 10, 100, 86, 28, -1, -1)
	GUICtrlSetBkColor(-1, "-2")
	GUICtrlCreateLabel("© sycam inc 2013", 10, 140, 113, 27, -1, -1)
	GUICtrlSetBkColor(-1, "-2")
	GUICtrlCreateLabel("created by: Sean Campbell", 10, 180, 110, 31, -1, -1)
	GUICtrlSetBkColor(-1, "-2")
	GUICtrlCreatePic(@scriptdir & "\CodeQ.bmp", 0, 0, 150, 54, -1, -1)
	GUISetState(@SW_SHOW, $settings)
	
	While 1
		$nMsg = GUIGetMsg()
		Switch $nMsg
			Case $GUI_EVENT_CLOSE
				If GUICtrlRead($au3rp) = "autoit run path" Then
				Else
					Global $au3run = GUICtrlRead($au3rp)
					IniWrite(@ScriptDir & "\api\au3\config.ini","config","runpath",$au3run)
				EndIf
				If GUICtrlRead($crp) = "C run path" Then
				Else
					Global $crun = GUICtrlRead($crp)
					IniWrite(@ScriptDir & "\api\c\config.ini","config","runpath",$crun)
				EndIf
				If GUICtrlRead($chrp) = "C# run path" Then
				Else
					Global $chrun = GUICtrlRead($chrp)
					IniWrite(@ScriptDir & "\api\C#\config.ini","config","runpath",$chrun)
				EndIf
				If GUICtrlRead($cpprp) = "C++ run path" Then
				Else
					Global $cpprun = GUICtrlRead($cpprp)
					IniWrite(@ScriptDir & "\api\C++\config.ini","config","runpath",$cpprun)
				EndIf
				If GUICtrlRead($jrp) = "java run path" Then
				Else
					Global $javarun = GUICtrlRead($jrp)
					IniWrite(@ScriptDir & "\api\java\config.ini","config","runpath",$javarun)
				EndIf
				If GUICtrlRead($jsrp) = "js run path" Then
				Else
					Global $jsrun = GUICtrlRead($jsrp)
					IniWrite(@ScriptDir & "\api\js\config.ini","config","runpath",$jsrun)
				EndIf
				If GUICtrlRead($lrp) = "lua run path" Then
				Else
					Global $luarun = GUICtrlRead($lrp)
					IniWrite(@ScriptDir & "\api\lua\config.ini","config","runpath",$luarun)
				EndIf
				If GUICtrlRead($fasrp) = "Flash As run path" Then
				Else
					Global $fasrun = GUICtrlRead($fasrp)
					IniWrite(@ScriptDir & "\api\fas\config.ini","config","runpath",$fasrun)
				EndIf
				If GUICtrlRead($phprp) = "Php run path" Then
				Else
					Global $phprun = GUICtrlRead($phprp)
					IniWrite(@ScriptDir & "\api\php\config.ini","config","runpath",$phprun)
				EndIf
				If GUICtrlRead($pyrp) = "Python run path" Then
				Else
					Global $pytrun = GUICtrlRead($pyrp)
					IniWrite(@ScriptDir & "\api\pyt\config.ini","config","runpath",$pytrun)
				EndIf
				GUIDelete($settings)
				ExitLoop
			Case $ab
				GUICtrlSetData($au3rp, _browse())
			Case $cb
				GUICtrlSetData($crp, _browse())
			Case $chb
				GUICtrlSetData($chrp, _browse())
			Case $cppb
				GUICtrlSetData($cpprp, _browse())
			Case $fasb
				GUICtrlSetData($fasrp, _browse())
			Case $jb
				GUICtrlSetData($jrp, _browse())
			Case $jsb
				GUICtrlSetData($jsrp, _browse())
			Case $luab
				GUICtrlSetData($lrp, _browse())
			Case $phpb
				GUICtrlSetData($phprp, _browse())
			Case $pyb
				GUICtrlSetData($pyrp, _browse())
		EndSwitch
	WEnd
EndFunc

Func _browse()
	return FileOpenDialog("browse for Executables", @ProgramFilesDir, "Executables (*.exe;*.com;*.bat;*.pif)")
EndFunc


Func _CLRL_read($sfile,$sector)
	Local $fa[1],$st = "[" & $sector & "]"
	_FileReadToArray($sFile,$fa)
	$stos = _ArraySearch($fa,$st) + 1
	$eos = _ArraySearch($fa,"/" & $st) - 1
	$String =  _ArrayToString($fa,@CR,$stos,$eos)
	If StringIsSpace($String) then
	msgbox(0,"","")
endif
	return $String
EndFunc

func _sci_int()
	SendMessageString($maxsci[$activesci][0], $SCI_SETKEYWORDS, 0,_CLRL_read(@ScriptDir & "\api\au3\au3.sc.clrl","keywords"))
	SendMessageString($maxsci[$activesci][0], $SCI_SETKEYWORDS, 1, _CLRL_read(@ScriptDir & "\api\au3\au3.sc.clrl","functions"))
	SendMessageString($maxsci[$activesci][0], $SCI_SETKEYWORDS, 2, _CLRL_read(@ScriptDir & "\api\au3\au3.sc.clrl","macros"))
	SendMessageString($maxsci[$activesci][0], $SCI_SETKEYWORDS, 3, _CLRL_read(@ScriptDir & "\api\au3\au3.sc.clrl","sendkeys"))
	SendMessageString($maxsci[$activesci][0], $SCI_SETKEYWORDS, 4, _CLRL_read(@ScriptDir & "\api\au3\au3.sc.clrl","prepro"))
	SendMessageString($maxsci[$activesci][0], $SCI_SETKEYWORDS, 7, _CLRL_read(@ScriptDir & "\api\au3\au3.sc.clrl","udfs"))
	sci_setlexer($MaxSci[$activesci][0],$SCLEX_AU3)
	$bits = SendMessage($MaxSci[$activesci][0], $SCI_GETSTYLEBITSNEEDED, 0, 0)
	SendMessage($MaxSci[$activesci][0], $SCI_SETSTYLEBITS, $bits, 0)
	SetStyle($MaxSci[$activesci][0], $STYLE_DEFAULT, 0x000000, 0xFFFFFF, 10, "Courier New")
	SendMessage($MaxSci[$activesci][0], $SCI_STYLECLEARALL, 0, 0)
	SetStyle($MaxSci[$activesci][0], $STYLE_BRACEBAD, 0x009966, 0xFFFFFF, 0, "", 0, 1)
	SetStyle($MaxSci[$activesci][0], $SCE_AU3_DEFAULT, 0x000000, 0xFFFFFF)
	SetStyle($MaxSci[$activesci][0], $SCE_AU3_NUMBER, 0xA900AC, 0xFFFFFF, 0, "", 1)
	SetStyle($MaxSci[$activesci][0], $SCE_AU3_STRING, 0xCC9999, 0xFFFFFF, 0, "", 1)
	SetStyle($MaxSci[$activesci][0], $SCE_AU3_OPERATOR, 0x0000FF, 0xFFFFFF, 0, "", 1)
	SetStyle($MaxSci[$activesci][0], $SCE_AU3_EXPAND, 0x0000FF, 0xFFFFFF, 0, "", 1)
	SetStyle($MaxSci[$activesci][0], $SCE_AU3_COMOBJ, 0xFF0000, 0xFFFFFF, 0, "", 1, 1)
	
EndFunc

Func _sci_au3()
	SetStyle($MaxSci[$activesci][0], $SCE_AU3_VARIABLE, 0x000090, 0xFFFFFF, 0, "", 1)
	SetStyle($MaxSci[$activesci][0], $SCE_AU3_SENT, 0x0080FF, 0xFFFFFF, 0, "", 1)
	SetStyle($MaxSci[$activesci][0], $SCE_AU3_UDF, 0xFF8000, 0xFFFFFF, 0, "", 1, 1)
	SetStyle($MaxSci[$activesci][0], $SCE_AU3_MACRO, 0xFF33FF, 0xFFFFFF, 0, "", 1)
	SetStyle($MaxSci[$activesci][0], $SCE_AU3_FUNCTION, 0xAA0000, 0xFFFFFF, 0, "", 1, 1)
	SetStyle($MaxSci[$activesci][0], $SCE_AU3_KEYWORD, 0xFF0000, 0xFFFFFF, 0, "", 1)
	SetStyle($MaxSci[$activesci][0], $SCE_AU3_PREPROCESSOR, 0xFF00F0, 0xFFFFFF, 0, "", 0, 0)
	SetStyle($MaxSci[$activesci][0], $SCE_AU3_SPECIAL, 0xF00FA0, 0xFFFFFF, 0, "", 0, 1)
	SetStyle($MaxSci[$activesci][0], $SCE_AU3_COMMENT, 0x339900, 0xFFFFFF)
	SetStyle($MaxSci[$activesci][0], $SCE_AU3_COMMENTBLOCK, 0x009966, 0xFFFFFF)
	SetStyle($Sci, $SCE_AU3_EXPAND, 0x0000FF, 0xFFFFFF, 0, "", 1)
	SetProperty($Sci, "fold", "1")
	SetProperty($Sci, "fold.compact", "1")
	SetProperty($Sci, "fold.comment", "1")
	SetProperty($Sci, "fold.preprocessor", "1")
	
		SendMessage($Sci, $SCI_SETMARGINTYPEN, $MARGIN_SCRIPT_FOLD, $SC_MARGIN_SYMBOL)
	SendMessage($Sci, $SCI_SETMARGINMASKN, $MARGIN_SCRIPT_FOLD, $SC_MASK_FOLDERS)
	SendMessage($Sci, $SCI_SETMARGINWIDTHN, $MARGIN_SCRIPT_FOLD, 20)
	SendMessage($Sci, $SCI_MARKERDEFINE, $SC_MARKNUM_FOLDER, $SC_MARK_ARROW)
	SendMessage($Sci, $SCI_MARKERDEFINE, $SC_MARKNUM_FOLDEROPEN, $SC_MARK_ARROWDOWN)
	SendMessage($Sci, $SCI_MARKERDEFINE, $SC_MARKNUM_FOLDEREND, $SC_MARK_ARROW)
	SendMessage($Sci, $SCI_MARKERDEFINE, $SC_MARKNUM_FOLDERMIDTAIL, $SC_MARK_TCORNER)
	SendMessage($Sci, $SCI_MARKERDEFINE, $SC_MARKNUM_FOLDEROPENMID, $SC_MARK_ARROWDOWN)
	SendMessage($Sci, $SCI_MARKERDEFINE, $SC_MARKNUM_FOLDERSUB, $SC_MARK_VLINE)
	SendMessage($Sci, $SCI_MARKERDEFINE, $SC_MARKNUM_FOLDERTAIL, $SC_MARK_LCORNER)
	SendMessage($Sci, $SCI_SETFOLDFLAGS, 16, 0)
	SendMessage($Sci, $SCI_MARKERSETFORE, $SC_MARKNUM_FOLDER, 0xFFFFFF)
	SendMessage($Sci, $SCI_MARKERSETBACK, $SC_MARKNUM_FOLDERSUB, 0x808080)
	SendMessage($Sci, $SCI_MARKERSETBACK, $SC_MARKNUM_FOLDEREND, 0x808080)
	SendMessage($Sci, $SCI_MARKERSETFORE, $SC_MARKNUM_FOLDEREND, 0xFFFFFF)
	SendMessage($Sci, $SCI_MARKERSETBACK, $SC_MARKNUM_FOLDERTAIL, 0x808080)
	SendMessage($Sci, $SCI_MARKERSETBACK, $SC_MARKNUM_FOLDERMIDTAIL, 0x808080)
	SendMessage($Sci, $SCI_MARKERSETBACK, $SC_MARKNUM_FOLDER, 0x808080)
	SendMessage($Sci, $SCI_MARKERSETFORE, $SC_MARKNUM_FOLDEROPEN, 0xFFFFFF)
	SendMessage($Sci, $SCI_MARKERSETBACK, $SC_MARKNUM_FOLDEROPEN, 0x808080)
	SendMessage($Sci, $SCI_MARKERSETFORE, $SC_MARKNUM_FOLDEROPENMID, 0xFFFFFF)
	SendMessage($Sci, $SCI_MARKERSETBACK, $SC_MARKNUM_FOLDEROPENMID, 0x808080)
	SendMessage($Sci, $SCI_SETMARGINSENSITIVEN, $MARGIN_SCRIPT_FOLD, 1)
EndFunc
Func _plugin_int()
	$pl = 1
	$plugindir = _FileListToArray(@ScriptDir & "\plugins")
	$plugdir = @ScriptDir & "\plugins\"
	Do
		$active = IniRead($plugdir & $plugindir[$pl] & "\plugin.ini","plugin","active",1)
		$plugin = IniRead($plugdir & $plugindir[$pl] & "\plugin.ini","Plugin","pluginfile","none")
		$pluginfile = @scriptdir & "\plugins\" & $plugindir[$pl] & "\" & $plugin
		If $active Then
		If $plugin = "none" Then
			MsgBox(0,"","invalid plugin : " & $plugindir[$pl])
		Else
			
		EndIf
		EndIf
		$pl = Execute("$pl+1")
	Until $pl = $plugindir[0] + 1
EndFunc